﻿@model XSTDZ.ERP.Application.DataContracts.ProductInBillDto
@using XSTDZ.ERP.Infrastructure.Extentions
@{
    ViewBag.Title = " - 新增入库单";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
     <style type="text/css">
        .none{ display:none;}
     </style>
}

<div class="wp100">
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    <tr>
        <td class="title"> @Html.LabelFor(model => model.ProductInBillNo)</td>
        <td> @Html.TextBoxFor(model => model.ProductInBillNo, new { @class = "text disablebg", @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.ProductInBillNo)
         <input type="hidden" value="@ViewBag.BillId" id="hidbillId" name="hidbillId" />
          @Html.HiddenFor(model => model.ID)
           @Html.HiddenFor(model => model.BillState)
        </td>

        <td class="title">@Html.LabelFor(model => model.ProductInDate)</td>
        <td>  @Html.TextBoxFor(model => model.ProductInDate, new { @class = "text" })
         <input type="hidden" value="@Model.ProductInDate" id="ProductInDateVal" name="ProductInDateVal" />
            @Html.ValidationMessageFor(model => model.ProductInDate)
         </td>
  </tr>


    <tr>
           <td class="title">仓库名称：</td>
        <td>      @Html.TextBoxFor(model => model.StorehouseName, new { @class = "text" })
         @Html.HiddenFor(model => model.StorehouseID)
            @Html.ValidationMessageFor(model => model.StorehouseName)
         </td>
           <td class="title">员工名称：</td>
        <td>   
         @Html.TextBoxFor(model => model.EmployeeName, new { @class = "text" })
         @Html.HiddenFor(model => model.EmployeeID)
         @Html.ValidationMessageFor(model => model.EmployeeName)
         </td>
    </tr>

     <tr>
         <td class="title">@Html.LabelFor(model => model.SourceOrgName)</td>
        <td>  @Html.TextBoxFor(model => model.SourceOrgName, new { @class = "text" })
             @Html.HiddenFor(model => model.SourceOrgID)
            @Html.ValidationMessageFor(model => model.SourceOrgName)
            <a href="javascript:void(0);" onclick="javascript:selectOrg();" >选择</a>
         </td>
          @*  <td class="title">@Html.LabelFor(model => model.SenderName)</td>
        <td>  @Html.TextBoxFor(model => model.SenderName, new { @class = "text none" })
        @Html.HiddenFor(model => model.SenderID)
        @Html.ValidationMessageFor(model => model.SenderName)
         </td>*@
         @Html.HiddenFor(model => model.SenderID)
   
           <td class="title">@Html.LabelFor(model => model.Remarks)</td>
        <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
            @Html.ValidationMessageFor(model => model.Remarks)
         </td>
        
         <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
    </tr>
@* @if (Model.BillState !=1)
  {*@
    <tr>
        <td  colspan="4">
              <p class="divBtn">
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="hidden" id="hidHttpPostState" name="hidHttpPostState" value="@ViewBag.PostState" />
             <input type="submit" value="" style="display:none;" id="BtnSubmitPost" name="BtnSubmitPost" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
@*  }*@
    </table>
    <input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@ViewBag.orgCode" />
        <input id="HidEmptyGuid" name="HidEmptyGuid" type="hidden" value="@Guid.Empty" />
}
</div>
<div class="wp100">
<input type="hidden" id="tempId" name="tempId"  value="@ViewBag.TempId" />
<div id="ProductInBillItemsGrid" style="margin-top:20px" ></div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#ProductInDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left'});
        var productInDateVal = $("#ProductInDateVal").val();
        $("#ProductInDate").ligerGetDateEditorManager().setValue(productInDateVal);

        //库房
        $("#StorehouseName").ligerPopupEdit({
            grid: getGridOptions(false),
            valueField: 'Id',
            textField: 'StorehouseName'
        });
        //添加用户
        getSelectUserGrid("EmployeeName");

        //添加送货人
//        $("#SenderName").ligerPopupEdit({
//            grid: getUserGridOptions(false),
//            valueField: 'Key',
//            textField: 'Name'
//        });

        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
    });
    function selectOrg() {
        var returnValue = window.showModalDialog('../Org/SelectOrgTree?selectType=1', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=300px;dialogHeight=300px");
        if (returnValue != null && returnValue != undefined) {
            $("#SourceOrgName").val(returnValue[0]);
            $("#SourceOrgID").val(returnValue[1]);
        }
    }
    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
                if (!validateGridDetail(manager, "InlCount")) { $.ligerDialog.success('明细数量不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                //  $("#BtnSubmitPost").click();
                //var formData=$("form").serialize();
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                // $.ajax({ type: "POST", url: "/ProductIn/Add", data: $('form').serialize(), // 要提交的表单
                $.ajax({ type: "POST", url: "/ProductIn/AddAndConfirm?isConfirm=" + isConfirm, data: $('form').serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                        }
                        else if (msg == "-1") {
                            $.ligerDialog.success('入库单明细数据不完整,操作失败!');
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    } 

</script>

<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
@*<script type="text/javascript" src="@Url.Content("~/Content/js/ProductInBill/SelectData.js")"></script>*@
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductInBill/Add.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>

